#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main() {
    int n, m, flag = 1;
    scanf("%d %d", &n, &m);
    int a[n][m], b[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &b[i][j]);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] != b[i][j])
            {
                flag = 0;
            }
        }
    }
    if (flag == 1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}